/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://github.com/mineadmin
 */

import type { MaSearchItem } from "@mineadmin/search";
import MaDictSelect from "@/components/ma-dict-picker/ma-dict-select.vue";
import MaRemoteSelect from "@/components/ma-remote-select/index.vue";
import { page as getDevicesList } from "$/attractions/inspection/api/inspectionDevices.ts";

export default function getSearchItems(t: any): MaSearchItem[] {
  return [
    {
      label: "事件类型",
      prop: "type",
      render: () => MaDictSelect,
      renderProps: {
        data: [
          { label: "故障", value: 1 },
          { label: "告警", value: 2 },
        ],
        placeholder: "请选择事件类型",
        clearable: true,
        multiple: false,
      },
    },
    {
      label: "异常时间",
      prop: "date",
      render: "DatePicker",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "异常时间" }),
        type: "datetimerange",
        "range-separator": "到",
        "start-placeholder": "开始日期",
        "end-placeholder": "结束日期",
        format: "YYYY-MM-DD HH:mm:ss",
        "value-format": "YYYY-MM-DD HH:mm:ss",
        "default-time": [
          new Date(2000, 1, 1, 0, 0, 0),
          new Date(2000, 2, 1, 23, 59, 59),
        ],
      },
    },
    {
      label: "处理状态",
      prop: "status",
      render: () => MaDictSelect,
      renderProps: {
        data: [
          { label: "已处理", value: 1 },
          { label: "未处理", value: 2 },
          { label: "已接收", value: 3 },
        ],
        placeholder: "请选择处理状态",
        clearable: true,
        multiple: false,
      },
    },
    {
      label: "巡检设备",
      prop: "devices",
      render: () => MaRemoteSelect,
      renderProps: {
        api: getDevicesList,
        dataHandle: (response: any) => {
          if (
            response.code === 200 &&
            response.data &&
            response.data.list
          ) {
            return response.data.list.map((item: any) => ({
              label: item.name || `设备${item.id}`,
              value: item.id,
            }));
          }
          return [];
        },
        placeholder: "请选择巡检设备",
        clearable: true,
        multiple: true,
      },
    }
  ];
}
